import shelve


class Model:
    def __init__(self, name='db-file'):
        self.name = 'dir_shelve/' + name

    def save(self, key, data):
        with shelve.open(self.name) as db:
            db[key] = data

    def get(self, key):
        with shelve.open(self.name) as db:
            data = db[key]
            return data

    def all(self):
        with shelve.open(self.name) as db:
            data = db.items()
            return dict(data)


obj = Model()
obj.save('k1', 'abcdef')
obj.save('k2', [1, 2, 3])
print(obj.get('k1'))
print(obj.all())
